<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增在职人员分析')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-select-css"/>
</head>
<style>
    input::-webkit-outer-spin-button, input::-webkit-inner-spin-button {
        -webkit-appearance: none;
    }

    input[type="number"] {
        -moz-appearance: textfield;
    }

</style>
<body>
<div class="wrapper wrapper-content ibox-content">
    <form class="form-horizontal m" id="czlrfy-edit" AUTOCOMPLETE="OFF">
        <input th:value="${data.id}" id="id" name="id" class="form-control" type="hidden"/>
        <h4 class="form-header h4">基本信息</h4>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">单位：</label>
                    <div class="col-sm-8">
                        <select name="compId" id="compId" class="form-control noselect2" disabled>
                            <option value="">请选择</option>
                            <option th:each="pro:${userComp}"
                                    th:selected="${data.compId==pro.compId}"
                                    th:value="${pro.compId}"
                                    th:text="${pro.compName}"></option>
                        </select>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">月末人数：</label>
                    <div class="col-sm-8">
                        <input id="monthEndNum" name="monthEndNum" th:value="${data.monthEndNum}"
                               class="form-control" type="text"
                               disabled/>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">年份：</label>
                    <div class="col-sm-8">
                        <input id="years" name="years" th:value="${data.years}" class="form-control" type="text"
                               disabled/>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">月份：</label>
                    <div class="col-sm-8">
                        <input id="months" name="months" th:value="${data.months}" class="form-control" type="text"
                               disabled/>
                    </div>
                </div>
            </div>
        </div>
        <h4 class="form-header h4">产值利润费用</h4>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">当月产值(万)：</label>
                    <div class="col-sm-8">
                        <input id="thisMonthsOutput"
                               onchange="thisMonthsOutputs()"
                               name="thisMonthsOutput" th:value="${data.thisMonthsOutput}"
                               class="form-control" type="number"
                               placeholder="请输入当月产值" required/>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">当月人均产值(万)：</label>
                    <div class="col-sm-8">
                        <input id="thisMonthsAvgOutput" name="thisMonthsAvgOutput"
                               th:value="${data.thisMonthsAvgOutput}" class="form-control"
                               type="number"
                               disabled/>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">总产值(万)：</label>
                    <div class="col-sm-8">
                        <input id="totalOutput" name="totalOutput" th:value="${data.totalOutput}"
                               class="form-control" type="number"
                               placeholder="请输入总产值"/>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">总人均产值(万)：</label>
                    <div class="col-sm-8">
                        <input id="totalAvgOutput" name="totalAvgOutput" th:value="${data.totalAvgOutput}"
                               class="form-control" type="number"
                        />
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">当月利润(万)：</label>
                    <div class="col-sm-8">
                        <input id="thisMonthsProfit" name="thisMonthsProfit" th:value="${data.thisMonthsProfit}"
                               onchange="thisMonthsProfits()"
                               class="form-control" type="number"
                               placeholder="请输入当月利润" required/>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">当月人均利润(万)：</label>
                    <div class="col-sm-8">
                        <input id="thisMonthsAvgProfit" name="thisMonthsAvgProfit"
                               th:value="${data.thisMonthsAvgProfit}" class="form-control"
                               type="number"
                               disabled/>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">总利润(万)：</label>
                    <div class="col-sm-8">
                        <input id="totalProfit" name="totalProfit" th:value="${data.totalProfit}"
                               class="form-control" type="number"
                               placeholder="请输入当总利润"/>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">总人均利润(万)：</label>
                    <div class="col-sm-8">
                        <input id="totalAvgProfit" name="totalAvgProfit" th:value="${data.totalAvgProfit}"
                               class="form-control" type="number"
                        />
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">当月费用(万)：</label>
                    <div class="col-sm-8">
                        <input id="thisMonthsCost" name="thisMonthsCost" th:value="${data.thisMonthsCost}"
                               onchange="thisMonthsCosts()"
                               class="form-control" type="number"
                               placeholder="请输入当月费用" required/>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">当月人均费用(万)：</label>
                    <div class="col-sm-8">
                        <input id="thisMonthsAvgCost" name="thisMonthsAvgCost" th:value="${data.thisMonthsAvgCost}"
                               class="form-control" type="number"
                               disabled/>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">总费用(万)：</label>
                    <div class="col-sm-8">
                        <input id="totalCost" name="totalCost" th:value="${data.totalCost}" class="form-control"
                               type="number" placeholder="请输入总费用"/>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">总人均费用(万)：</label>
                    <div class="col-sm-8">
                        <input id="totalAvgCost" name="totalAvgCost" th:value="${data.totalAvgCost}"
                               class="form-control" type="number"
                        />
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">
    var prefix = ctx + 'czlrfy';
    var sumThisMonthsOutput = 0;//总产值
    var thisMonthsProfit = 0;//总利润
    var thisMonthsCost = 0;//总费用
    var sumMonthEndNum = 0;//总月末人数

    $(function () {
        $.ajax({
            url: prefix + '/getTotalOutPut',//产值
            type: 'POST',
            data: {
                compId: $("#compId").val(),
                years: Number($("#years").val()),
                months: Number($("#months").val()),
            },
            success: function (data) {
                sumThisMonthsOutput = data.data.ThisMonthsOutputSum;
                sumMonthEndNum = data.data.sumMonthEndNum;
                //$("#totalOutput").val(sumThisMonthsOutput);

            }

        })



    })

    function thisMonthsOutputs() {
        var thisMonthsOutputs = (Number($("#thisMonthsOutput").val()) / Number($("#monthEndNum").val())).toFixed(2); //当月人均产值
        var sumMonthEndNums = sumMonthEndNum + Number($("#monthEndNum").val());//总月末人数
        var sumThisMonthsOutputs = sumThisMonthsOutput + Number($("#thisMonthsOutput").val());//总产值
        $("#thisMonthsAvgOutput").val(thisMonthsOutputs);
        //$("#totalOutput").val(sumThisMonthsOutputs);
        //$("#totalAvgOutput").val((sumThisMonthsOutputs / sumMonthEndNums).toFixed(2));//总人均产值

    }

    function thisMonthsProfits() {
        var thisMonthsAvgProfit = (Number($("#thisMonthsProfit").val()) / Number($("#monthEndNum").val())).toFixed(2); //当月人均利润
        var sumMonthEndNums = sumMonthEndNum + Number($("#monthEndNum").val());//总月末人数
        var thisMonthsProfits = thisMonthsProfit + Number($("#thisMonthsProfit").val());//总利润
        $("#thisMonthsAvgProfit").val(thisMonthsAvgProfit);
        // $("#totalProfit").val(thisMonthsProfits);
        //$("#totalAvgProfit").val((thisMonthsProfits / sumMonthEndNums).toFixed(2));//总人均利润

    }

    function thisMonthsCosts() {
        var thisMonthsAvgCost = (Number($("#thisMonthsCost").val()) / Number($("#monthEndNum").val())).toFixed(2); //当月人均费用
        var sumMonthEndNums = sumMonthEndNum + Number($("#monthEndNum").val());//总月末人数
        var thisMonthsCosts = thisMonthsCost + Number($("#thisMonthsCost").val());//总费用
        $("#thisMonthsAvgCost").val(thisMonthsAvgCost);
        // $("#totalCost").val(thisMonthsCosts);
        //$("#totalAvgCost").val((thisMonthsCosts / sumMonthEndNums).toFixed(2));//总人均利润
    }

    function submitHandler() {
        if ($.validate.form()) {
            $("input").removeAttr('disabled');
            $("select").removeAttr('disabled');
            var data = $("#czlrfy-edit").serializeArray();
            $.operate.save(prefix + "/edit", data);
            //parent.sum();

        }
    }

</script>
</body>
</html>